Page({
  data: {
    passport: {},
  },
  onLoad({ id, encryptedData }) {
    // console.log(id)
    if (id) {
      this.getPassport(id)
    } else {
      this.getPassportShare(encryptedData)
    }
  },
  async getPassport(id) {
    const { code, data: passport } = await wx.http.get('/visitor/' + id)
    if (code !== 10000) return wx.utils.toast('请求失败')
    this.setData({ passport })
  },
  async getPassportShare(encryptedData) {
    const { code, data: passport } = await wx.http.get('/visitor/share/' + encryptedData)
    if (code != 10000) return wx.utils.toast('请求失败')
    this.setData({ passport })
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData=' + this.data.passport.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  // 保存二维码到相册
  async saveQRCode() {
    const { path } = await wx.getImageInfo({ src: this.data.passport.url })
    console.log(path)
    wx.saveImageToPhotosAlbum({ filePath: path })
  },
})
